﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace Rage.UI
{
    public partial class GemmingTemplateItem : UserControl
    {
        public bool isCustom;

        public GemmingTemplate template;
        private GemmingTemplates parent;

        public GemmingTemplateItem(GemmingTemplates parent, GemmingTemplate template)
        {
            this.parent = parent;
            this.template = template;
            DataContext = template;
            isCustom = template.Group == "Custom";
            InitializeComponent();

            template.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(template_PropertyChanged);

            if (isCustom) DeleteButton.Visibility = Visibility.Visible;
            else DeleteButton.Visibility = Visibility.Collapsed;
        }

        private void template_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            if (e.PropertyName == "Enabled")
            {
                parent.UpdateGroupChecked(template.Group);
            }
        }

        private void MouseEnterButton(object sender, MouseEventArgs e)
        {
            Button itemButton = sender as Button;
            if (itemButton != null)
            {
                MainPage.Tooltip.Item = itemButton.Tag as Item;
                MainPage.Tooltip.Show(itemButton, itemButton.ActualWidth + 4, 0);
            }
        }

        private void MouseLeaveButton(object sender, MouseEventArgs e)
        {
            Button itemButton = sender as Button;
            if (itemButton != null)
            {
                MainPage.Tooltip.Hide();
            }
        }

        private void ArmoringButtonClick(object sender, RoutedEventArgs e) { if (isCustom) parent.ArmoringButtonClick(template.Armoring, sender as Button, ArmoringChanged); }
        private void BarrelButtonClick(object sender, RoutedEventArgs e) { if (isCustom) parent.BarrelButtonClick(template.Armoring, sender as Button, BarrelChanged); }
        private void HiltButtonClick(object sender, RoutedEventArgs e) { if (isCustom) parent.HiltButtonClick(template.Armoring, sender as Button, Hilthanged); }
        private void ModButtonClick(object sender, RoutedEventArgs e) { if (isCustom) parent.ModButtonClick(template.Armoring, sender as Button, ModChanged); }
        private void EnhancementButtonClick(object sender, RoutedEventArgs e) { if (isCustom) parent.EnhancementButtonClick(template.Armoring, sender as Button, EnhancementChanged); }
        private void ColorCrystalButtonClick(object sender, RoutedEventArgs e) { if (isCustom) parent.ColorCrystalButtonClick(template.Armoring, sender as Button, ColorCrystalChanged); }
        private void AugmentButtonClick(object sender, RoutedEventArgs e) { if (isCustom) parent.AugmentButtonClick(template.Armoring, sender as Button, AugmentChanged); }
        private void ArmoringChanged(Item newMod) { if (isCustom) template.Armoring = newMod; }
        private void BarrelChanged(Item newMod) { if (isCustom) template.Barrel = newMod; }
        private void Hilthanged(Item newMod) { if (isCustom) template.Hilt = newMod; }
        private void ModChanged(Item newMod) { if (isCustom) template.Mod = newMod; }
        private void EnhancementChanged(Item newMod) { if (isCustom) template.Enhancement = newMod; }
        private void ColorCrystalChanged(Item newMod) { if (isCustom) template.ColorCrystal = newMod; }
        private void AugmentChanged(Item newMod) { if (isCustom) template.Augment = newMod; }

        private void DeleteTemplate(object sender, RoutedEventArgs e)
        {
            parent.RemoveTemplate(this);
        }

    }
}